package com.example.myapplication.tack_14.adapter;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.R;

import com.example.myapplication.tack_14.DetailsActivity;
import com.example.myapplication.tack_14.data.ArrangeData;
import com.example.myapplication.utils.Common;
import com.example.myapplication.utils.OkHttpTool;

import java.util.List;

public class ArrangeAdapter extends RecyclerView.Adapter<ArrangeAdapter.My> {
    private List<ArrangeData.RowsDTO> list;
    private Context context;
    private View view;

    public ArrangeAdapter(List<ArrangeData.RowsDTO> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @NonNull
    @Override
    public My onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(context).inflate(R.layout.tack_14_arrange,null);
        return new My(view);
    }

    @Override
    public void onBindViewHolder(@NonNull My holder, int position) {
        Glide.with(context).load(OkHttpTool.URL + list.get(position).getImgUrl()).into(holder.imags);

        holder.title.setText(list.get(position).getTitle());
        String s = (list.get(position).getCreateTime()).toString();
        holder.createTime.setText(s);
        holder.createTime.setText("");

        holder.line.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String id = String.valueOf(list.get(position).getId());
                Intent intent = new Intent(context, DetailsActivity.class);
                intent.putExtra(Common.COMMON,id);
                context.startActivity(intent);

            }
        });
    }

    @Override
    public int getItemCount() {
        return list != null?list.size():0;
    }

    public class My extends RecyclerView.ViewHolder{
        private ImageView imags;
        private TextView title;
        private TextView createTime;

        private LinearLayout line;
        public My(@NonNull View itemView) {
            super(itemView);
            imags = view.findViewById(R.id.imags);
            title = view.findViewById(R.id.title);
            createTime = view.findViewById(R.id.createTime);
            line = view.findViewById(R.id.line);
        }
    }
}
